<style>
    .layui-form .layui-form-item .layui-inline input{
        width: 200px;
    }
</style>
<form class="layui-form seller-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" style="width:150px">用户名称：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="username" placeholder="username" autocomplete="off"
                       maxlength="50" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" style="width:150px">Create Time：</label>
            <div class="layui-input-inline seller-inline-4">
                <input type="text" name="datetime" id="datetime" placeholder="start_time _ end_time" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>Search</button>
                <!--<a href="javascript:;" class="layui-btn layui-btn-sm" id="add"><i class="layui-icon">&#xe608;</i>Add</a>-->
            </div>
        </div>
    </div>
</form>
<div class="table-body">
    <table id="balanceTable" lay-filter="balanceTable"></table>
</div>
<script>
    layui.use(['form', 'laydate', 'table',], function () {
        var laydate = layui.laydate,
            form = layui.form,
            table = layui.table; //表格
        //时间插件
        laydate.render({
            elem: '#datetime',
            range: '_',
            format: 'yyyy-MM-dd'
        });
        var tableIn = table.render({
            elem: '#balanceTable',
            height: 'full-99',
            cellMinWidth: '80',
            // totalRow: true,
            method: 'post',
            url: "{:url('userSetLog')}",
            id: 'balanceTable',
            cols: [[
                { type: 'numbers'},
                { field: 'un', align: 'left', title: '操作管理员', width:200},
                { field: 'username', align: 'left', title: '用户', width:200 ,
                    templet:function (d) {
                        const user_id=   d.user_id;
                        if(user_id != 0){
                            return d.username;
                        }else{
                            return '默认设置';
                        }
                    }
                },
                { field: 'type', align: 'left', title: '用户类型', width:200 ,
                    templet:function (d) {
                        const type=   d.type;
                        if(type == 0){
                            return '新用户创建';
                        }else if(type == 1){
                            return '<span style="color: green">老用户更新</span>';
                        }
                    }
                },
                { align: 'left', title: '创建时间',width:200,
                    templet: function (d) {
                        const ctime = d.ctime;
                        if(ctime == undefined){
                            return '--';
                        }else{
                            return layui.util.toDateString(d.ctime * 1000, "yyyy-MM-dd HH:mm:ss");
                        }
                    }
                },
                { field: 'option', title: 'Action', templet: function (d) {
                        return '<a class="layui-btn layui-btn-xs SearchDetail" data-id="' + d.id + '">info</a>';
                    }, align: 'center', width: 80
                }
            ]],
            page: true,
            limit: 20,
            limits: [20, 50, 100],
        });
        form.on('submit(*)', function (data) {
            layui.table.reload('balanceTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //余额编辑
        $(document).on('click', '.SearchDetail', function () {
            var id = $(this).attr('data-id');
            JsGet("{:url('showUserSet')}?type=change&id="+ id, function(e){
                if(e.status == 1){
                    layer.open({
                        type: 1,
                        title: 'Log Detail',
                        area: ['1000px', '600px'], //宽高
                        content: e.datas,
                        btn:['Close']
                    });
                }else{
                    layer.msg(e.msg);
                }
            });
        });
    });
</script>